/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "hchotnodewaterline_fuzzer.h"

const char hc_hot_node_waterline[] = "/sys/fs/f2fs/loop1/hc_hot_node_waterline";

namespace OHOS {
bool HcHotNodeWaterline(const uint8_t* data, size_t size)
{
	char buffer[sizeof(char)];
	int fd = open(hc_hot_node_waterline, RDWR);
	if (fd < 0) {
        printf("open %s failed\r\n", hc_hot_node_waterline);
        return false;
    }
	int ret = read(fd,buffer,sizeof(char));
	if(ret == 0){
		printf("%s read success", hc_hot_node_waterline);
	}
	ret = write(fd, data, sizeof(char));
	
	if(ret == 0){
		printf("%s write success", hc_hot_node_waterline);
	}
	close(fd);
    return true;
}
}

/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
    /* Run your code on data  hc_hot_data_lower_limit*/
    OHOS::HcHotNodeWaterline(data, size);
    return 0;
}

